package com.yongqi.duocai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yongqi.duocai.entity.User;
import com.yongqi.duocai.mapper.UserMapper;
import com.yongqi.duocai.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 夏亮辉
 * @since 2021-06-22
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据 openid 查询用户信息
     * @param openid
     * @return
     */
    @Override
    public User selectByOpenId(String openid) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("openid", openid);
        return userMapper.selectOne(queryWrapper);
    }

    /**
     * 根据 电话查找用户信息
     *
     * @param phone
     * @return
     */
    @Override
    public User selectByPhone(String phone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }
}
